package br.com.andreikeda.utility.gestor.finance.storage.preferences;

import android.content.Context;
import android.content.SharedPreferences;

import br.com.andreikeda.utility.gestor.R;

/**
 * Created by ikeda on 22/01/15.\n\n
 * Contact: <b>andreikeda87@gmail.com</b> or <b>andre.ikeda@99motos.com</b>
 */
public class Preferences {

    private static Preferences instance;

    private final String IS_FIRST_TIME = "is_first_time";

    private SharedPreferences mPref;
    private SharedPreferences.Editor mEditor;

    public static Preferences getInstance(Context context) {
        if (instance == null)
            instance = new Preferences(context);
        return instance;
    }

    public synchronized boolean isFirstTime() {
        return mPref.getBoolean(IS_FIRST_TIME, true);
    }

    public synchronized void onIsFirstTimeChanged(boolean isFirstTime) {
        mEditor.putBoolean(IS_FIRST_TIME, isFirstTime).apply();
    }

    private Preferences(Context context) {
        mPref = context.getSharedPreferences(context.getString(R.string.app_name), Context.MODE_PRIVATE);
        mEditor = mPref.edit();
    }

}
